
const Sponsor = require('../model/sponsor.model')

class sponsorService {
  async getSponsor(params){
    const { count, rows } = await Sponsor.findAndCountAll(
      {
        limit:params.pageSize,
        offset:(params.pageNo -1) * params.pageSize 
      },
    )
    return {
      rows,
      count
    }
  }
  //新增
  async insertItem(params){
    const res = await Sponsor.create(params)
    return res
  }
  //修改
  async updateItem(params){
    const res = await Sponsor.update(
      {...params},
      { where:{id:params.id} }
    )
    return res
  }
  //删除
  async deleteOne(params){
    const res = await Sponsor.destroy({ where:{ id:params.id } })
    return res
  }
  //查询一条信息
  async getOne(params){
    const res = await Sponsor.findOne({
      where:{ id:params.id }
    })
    return res
  }
}

module.exports = new sponsorService()